#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#![allow(dead_code)]
#![allow(unused)]
use std::sync::atomic::*;
use std::collections::HashMap;
static mut cgienv: [[&str; 2]; 1] = [
    ["GOOD", "gdsfsd"],
];
/*
** Double any double-quote characters in a string.
** 将字符串中的双引号加倍
*/
pub fn escape(z: &str) -> String {
    let mut res = String::new();
    for ch in z.chars() {
        if ch == '"' {
            res.push(ch);
            res.push(ch);
        } else {
            res.push(ch);
        }
    }
    res
}
pub fn make_log_entry(exitCode: i32, linenum: i32) {

}
pub fn safe_malloc() {
    // useless in rust
    // deprecated
}
pub fn set_env(zVar: &str, zValue: &str) {
    if zValue.starts_with("() {") {
        std::env::set_var(zVar, "");
    } else {
        std::env::set_var(zVar, zValue);
    }
}
pub struct CgienvStruct {
    z_env_name: String,
    pz_env_value: String,
}
pub fn get_first_element(mut zInput: &str, zLeftOver: &str) -> Option<String> {
    // use split_whitespace instead!!!
    // deprecated
    None
}
pub fn str_dup(zSrc: &str) -> String {
    zSrc.to_string()
}
pub fn str_append(zPrior: &str, zSep: &str, zSrc: &str) -> String {
    if zSrc.is_empty() || zPrior.is_empty() {
        zSrc.to_string()
    } else {
        let mut res = String::from(zPrior);
        res += zSep;
        res += zSrc;
        res
    }
}
pub fn compare_etags(za: &str, zb: &str) -> bool {
    if za.is_empty() {
        return true;
    }
    if za.starts_with('"') {
        let zab = za.as_bytes();
        let zbb = zb.as_bytes();
        let lenb = zbb.len();
        if &zab[1..] == zbb && zab.len() > 1 + lenb && zab[1 + lenb] == '"' as u8 {
            return false;
        }
    }
    return za == zb;
}
pub fn remove_new_line(z: &str) {
    // use split_line instead
    // deprecated
}
pub fn Rfc822Date(t: u64) -> String {
    use std::time::{SystemTime, Duration};
    // let mut nowtime = SystemTime::UNIX_EPOCH;
    // nowtime += Duration::from_secs(t);
    // format!("{:?}", nowtime)
    format!("{:?}", Duration::from_secs(t))
}
pub fn all_test() {
    assert_eq!(&escape("a\"b\"c"), "a\"\"b\"\"c");
    set_env("ALTHTTPD_TEST", "TRUE");
    assert_eq!(std::env::var("ALTHTTPD_TEST"), Ok("TRUE".to_string()));
    assert_eq!(str_append("A", " ", "B"), "A B".to_string());
    assert_eq!(str_append("", "abc", "B"), "B".to_string());
    assert_eq!(compare_etags("ab", "ba"), false);
    assert_eq!(compare_etags("ab", "\"ab\""), false);
    assert_eq!(compare_etags("\"ab", "\"ab"), true);
    assert_eq!(compare_etags("\"ab\"", "\"ab"), false);
    println!("[INFO] ALL CHECK HAS BEEN DONE!");
}
pub fn main() {
    all_test();
    unsafe {
        println!("{:?}", cgienv);
    }
    println!("{:?}",Rfc822Date(1000000));
}
